/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package logical_spaces.business;

import Entity.TableSpace;
import Entity.TableSpaceInfo;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author juan
 */
public class TableSpaceInfoDataModel extends ListDataModel<TableSpaceInfo> implements SelectableDataModel<TableSpaceInfo>{

    public TableSpaceInfoDataModel() {
    }

    public TableSpaceInfoDataModel(List<TableSpaceInfo> data) {
        super(data);
    }
    
    @Override  
    public TableSpaceInfo getRowData(String rowKey) {  
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
          
        List<TableSpaceInfo> tableSpaces = (List<TableSpaceInfo>) getWrappedData();  
          
        for(TableSpaceInfo table : tableSpaces) {  
            if(table.getNombre().equals(rowKey))  
                return table;  
        }  
          
        return null;  
    }  
  

    @Override
    public Object getRowKey(TableSpaceInfo table) {
        return table.getNombre();
    }
    
}
